package com.api.gbhg.lbj.action;

import com.api.gbhg.lbj.dao.LoanrepaymentDao;
import com.api.gbhg.lbj.dao.ReimbursementDao;
import com.api.gbhg.zengping.common.CommonDao;
import com.api.gbhg.zengping.web.PropertyManagementAction;
import com.weaver.general.BaseBean;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.workflow.WorkflowVersion;

import java.util.HashMap;
import java.util.Map;

import static com.api.gbhg.lbj.tool.Tools.getsfkzsydwbxed;

/**
 * @author lbj
 * @version 1.0
 * @description: TODO 借款流程
 * @date 2021/10/26 16:47
 */
public class loanAction implements Action {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");

    @Override
    public String execute(RequestInfo requestInfo) {
        logger.info("进入-借款流程-loanAction---");
        ReimbursementDao rei = new ReimbursementDao();
        //请求id
        String requestid = requestInfo.getRequestid();
        //获取表名
        String billTableName = requestInfo.getRequestManager().getBillTableName();
        LoanrepaymentDao loa = new LoanrepaymentDao();
        RecordSet rs = CommonDao.selectByRequestId(new RecordSet(), billTableName, requestid);
        RecordSetTrans rst = new RecordSetTrans();
        rst.setAutoCommit(false);
        if (rs.next()) {
            Map<String, String> list = new HashMap<>();
            String ysxm = rs.getString("ysxm");
            String bxje = rs.getString("sqbxje");//借款金额
            String bmjjzcfl = rs.getString("bmjjzcfl");
            String zcqd = rs.getString("zcqd");
            String ysly = rs.getString("ysly");
            String fzysrfl = rs.getString("fzysrfl");
            String xzkmdm = rs.getString("xzkmdm");
            String zcdfczbkxm = rs.getString("zcdfczbkxm");
            String nd = rs.getString("nd");
            String dw = rs.getString("szdlhsdw");
            String jbbm = rs.getString("jbbm");

            list.put("zcqd", zcqd);//支出渠道
            list.put("ysly", ysly);//预算来源
            list.put("nd", nd);//年度
            list.put("fzysrfl", fzysrfl);//非中央收入分类
            list.put("xzkmdm", xzkmdm);//选择科目代码
            list.put("zcdfczbkxm", zcdfczbkxm);//地方财政拨款项目
            list.put("dw", dw);//单位
            list.put("jbbm", jbbm);//经办部门
            list.put("lcjlid", ysxm);//预算项目
            list.put("money", bxje);//借款金额
            list.put("bmzcjjfl", bmjjzcfl);//部门经济支出分类
            logger.info("预算项目:" + ysxm + "借款金额:" + bxje + "部门经济支出分类:" + bmjjzcfl);

            boolean b = true;
            try {
                b = loa.jhkMainJingfei(rst,list, true); // jingfei表 true:扣款  false:还款
                if (b) {
                    b = loa.jhkjingfeily(rst,list, true);// jinfei来源和收入 true:扣款  false:还款
                }
                logger.info("b:" + b);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (!b) {
                rst.rollback();
                logger.info("=====================借款失败=======================");
                requestInfo.getRequestManager().setMessagecontent("借款扣减金额失败");
                requestInfo.getRequestManager().setMessageid("1");
                return FAILURE_AND_CONTINUE;
            }
        }
        rst.commit();
        return Action.SUCCESS;
    }
}
